package licode.unisop.realm.application.executor;

import licode.unisop.provider.info.UserIdInfo;
import licode.unisop.provider.vo.SiIdentitySet;
import licode.unisop.realm.application.gateway.SiRealmModelGateway;
import licode.unisop.realm.client.api.SiIdentityQueryService;
import licode.unisop.realm.domainx.model.RealmModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户认证信息查询
 *
 * @author licode
 */
@Service
public class SiIdentityQueryExecutor implements SiIdentityQueryService {
    @Resource
    private SiRealmModelGateway siRealmModelGateway;

    @Override
    public SiIdentitySet findIdentity(UserIdInfo idFind) {
        RealmModel realm = siRealmModelGateway.findRealmModel(idFind.getRealmId());
        return null == realm || realm.getProvider() == null ? null
                : realm.getProvider().findIdentity(UserIdInfo.builder()
                .userId(idFind.getUserId())
                .realmId(idFind.getRealmId())
                .clientId(idFind.getClientId())
                .platformId(idFind.getPlatformId())
                .build());
    }
}
